<?php

class esb_certificate {
	
	/**
	 * 生成证书
	 * 证书规则
	 * 日期+地区id_流水号
	 * 20130129_05373_000001
	 */
	function gen_id($areaid) {
		
		$sql = 'SELECT max( `id` ) as id FROM `sdb_esb_certificate`';
		
		$max = kernel::database ()->selectrow ( $sql );
		
		$maxid = $max ['id'];
		$maxid = $maxid + 1;
		$maxid = sprintf ( "%04d", $maxid ); // 生成8位数，不足前面补0		
		$areaid = sprintf ( "%04d", $areaid );
		
		$certi_id = date ( "Ymd" ) . $areaid .  $maxid;
		//echo $certi_id;
		return $certi_id;
	
	}
	function gen_token($certi_id) {
		
		$token = md5 ( (( float ) date ( "YmdHis" ) + rand ( 10000000000000000, 99999999999999999 )) . rand ( 100000, 999999 ) . $certi_id );
		//echo $token;
		return $token;
	
	}

}